unit Class_ZBD_SL;
//simple tbl_zbd_fl

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TZBDSL=class(TUniEngine)
  private
    FZBDDWBML : string;
    FZBDFLBJKM: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property ZBDDWBML : string read FZBDDWBML  write FZBDDWBML;
    property ZBDFLBJKM: string read FZBDFLBJKM write FZBDFLBJKM;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AZBDFL:TZBDSL):TZBDSL;overload;        
    class procedure CopyIt(AZBDFL:TZBDSL;var Result:TZBDSL);overload;       
  end;

implementation

{ TZBDSL }
procedure TZBDSL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('ZBD_DWBML').Value := ZBDDWBML;
        ParamByName('ZBD_FL_BJKM').Value := ZBDFLBJKM; 
      end;
      otEdit:
      begin
        ParamByName('ZBD_DWBML').Value := ZBDDWBML;
        ParamByName('ZBD_FL_BJKM').Value := ZBDFLBJKM; 
      end;  
      otDelt:
      begin
        ParamByName('ZBD_DWBML').Value := ZBDDWBML;
        ParamByName('ZBD_FL_BJKM').Value := ZBDFLBJKM; 
      end;  
    end;
  end;
end;

function TZBDSL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_ZBD_FL',['ZBD_DWBML',ZBDDWBML,'ZBD_FL_BJKM',ZBDFLBJKM],AUniConnection);
end;

function TZBDSL.GetNextIdex: Integer;
begin

end;

function TZBDSL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TZBDSL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_ZBD_FL WHERE   ZBD_DWBML=:ZBD_DWBML AND ZBD_FL_BJKM=:ZBD_FL_BJKM';
end;

function TZBDSL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_ZBD_FL'
         +'    ( ZBD_DWBML, ZBD_FL_BJKM)'
         +'    VALUES'
         +'    (:ZBD_DWBML,:ZBD_FL_BJKM)';
end;

function TZBDSL.GetStrsIndex: string;
begin
  Result:=Format('%S-%S',[ZBDDWBML,ZBDFLBJKM]);
end;

function TZBDSL.GetStrUpdate: string;
begin
  raise Exception.Create('CAN NOT SUPPORT GETSTRUPDATE METHOD.CAUSE ALL THIS TABLE FILEDS ARE PRIMARY KEY.')
end;

constructor TZBDSL.Create;
begin

end;

destructor TZBDSL.Destroy;
begin

  inherited;
end;

class function TZBDSL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TZBDSL.Create;
  with TZBDSL(Result) do
  begin
    ZBDDWBML :=AUniQuery.FieldByName('ZBD_DWBML').AsString;
    ZBDFLBJKM:=AUniQuery.FieldByName('ZBD_FL_BJKM').AsString;
  end;  
end;

class procedure TZBDSL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TZBDSL(Result) do
  begin
    ZBDDWBML :=AUniQuery.FieldByName('ZBD_DWBML').AsString;
    ZBDFLBJKM:=AUniQuery.FieldByName('ZBD_FL_BJKM').AsString;
  end;  
end;

class function  TZBDSL.CopyIt(AZBDFL: TZBDSL): TZBDSL;
begin
  Result:=TZBDSL.Create;
  TZBDSL.CopyIt(AZBDFL,Result)
end;

class procedure TZBDSL.CopyIt(AZBDFL:TZBDSL;var Result:TZBDSL);
begin
  if Result=nil then Exit;
  Result.ZBDDWBML :=AZBDFL.ZBDDWBML;
  Result.ZBDFLBJKM:=AZBDFL.ZBDFLBJKM;
end;

end.
